package com.bitdf.txing.group.feign.impl.order;

import com.bitdf.txing.common.enume.TxCodeEnume;
import com.bitdf.txing.common.to.SkuHasStockVo;
import com.bitdf.txing.common.utils.R;
import com.bitdf.txing.order.feign.OrderWmsFeignService;
import com.bitdf.txing.order.vo.WareSkuLockVo;
import com.bitdf.txing.ware.service.WareInfoService;
import com.bitdf.txing.ware.service.WareSkuService;
import com.bitdf.txing.ware.vo.FareVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Lizhiwei
 * @date 2023/9/5 23:31:32
 * 注释：
 */
@Service
@ConditionalOnProperty(value = "tx.deploy.mode", havingValue = "standalone")
public class OrderWmsFeignServiceImpl implements OrderWmsFeignService {
    @Autowired
    WareSkuService wareSkuService;
    @Autowired
    WareInfoService wareInfoService;
    @Override
    public R getSkuHasStock(List<Long> skuIds) {
        List<SkuHasStockVo> vos = wareSkuService.getSkusHasStock(skuIds);
        return R.ok().setData(vos);
    }

    @Override
    public R getFare(Long addrId) {
        FareVo fare = wareInfoService.getFare(addrId);
        return R.ok().setData(fare);
    }

    @Override
    public R orderLockStock(WareSkuLockVo vo) {
        com.bitdf.txing.ware.vo.WareSkuLockVo wareSkuLockVo = new com.bitdf.txing.ware.vo.WareSkuLockVo();
        BeanUtils.copyProperties(vo, wareSkuLockVo);
        try{
            Boolean stock = wareSkuService.orderLockStock(wareSkuLockVo);
            return R.ok();
        }catch (Exception e){
            return R.error(TxCodeEnume.WARE_NOT_STOCK_EXCEPTION);
        }
    }
}
